//
//  MyNavigation.m
//  MyNavigationC
//
//  Created by 零零壹 on 2017/3/8.
//  Copyright © 2017年 零零壹. All rights reserved.
//

#import "MyNavigation.h"

@interface MyNavigation ()

@end

@implementation MyNavigation

- (void)viewDidLoad {
    [super viewDidLoad];
    UINavigationBar *navBar = [UINavigationBar appearance];
    [navBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    navBar.tintColor    = [UIColor whiteColor];
    navBar.shadowImage  = [[UIImage alloc] init]; //去掉下面的线
    navBar.translucent  = NO;//去掉透明度
    NSDictionary *barTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIColor whiteColor],NSForegroundColorAttributeName,
                                            [UIFont fontWithName:@"System-Light" size:40],NSFontAttributeName, nil];

    self.navigationItem.backBarButtonItem.title = @"";
    self.navigationItem.leftBarButtonItem.title = @"";
    
    [navBar setTitleTextAttributes:barTitleTextAttributes];
    [[self.viewControllers lastObject] setTitle:@""];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [super pushViewController:viewController animated:YES];

    if (viewController.navigationItem.leftBarButtonItem == nil  && viewController != [self.viewControllers firstObject])
    {
        UIButton *leftbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        leftbutton.frame= CGRectMake(0, 10, 44, 44);
        leftbutton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
        [leftbutton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *leftBarbutton = [[UIBarButtonItem alloc] initWithCustomView:leftbutton];
        [leftbutton setImage:[[UIImage imageNamed:@"left"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] forState:(UIControlStateNormal)];
        viewController.navigationItem.leftBarButtonItem = leftBarbutton;
    }
    
    //设置默认的导航栏标题
    viewController.title = @"";
}


#pragma mark 设置按钮动作
- (void)backAction:(UIBarButtonItem *)sender
{
    [self popViewControllerAnimated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
